define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'violation/index' + location.search,
                    add_url: 'violation/add',
                    edit_url: 'violation/edit',
                    del_url: 'violation/del',
                    multi_url: 'violation/multi',
                    import_url: 'violation/import',
                    table: 'violation',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'store_id', title: __('Store_id')},
                        // {field: 'car_id', title: __('Car_id')},
                        // {field: 'zhifa_id', title: __('Zhifa_id')},
                        {field: 'car.plate_number', title: __('Car.plate_number'), operate: 'LIKE'},
                        {field: 'store.store_name', title: __('Store.store_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_illegal', title: __('Is_illegal'), searchList: {"1":__('Is_illegal 1'),"2":__('Is_illegal 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'pic', title: __('Pic'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'add_time', title: __('Add_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'edit_time', title: __('Edit_time'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_edit', title: __('Is_edit'), searchList: {"0":__('Is_edit 0'),"1":__('Is_edit 1')}, formatter: Table.api.formatter.normal},
                        {field: 'zhifa.name', title: __('执法人姓名'), operate: 'LIKE'},
                        
                        
                        {field: 'product.title', title: __('Product.title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                            
                            {
                                name: 'changelog',
                                title: '变动记录',
                                extend:'data-area=["1000px","730px"]',
                                text:'变动记录',
                                //height:'500px',
                                classname: 'btn btn-xs btn-waring btn-primary btn-dialog',
                                url: 'violationlog?ids={id}',
                                callback: function (data) {
                                    //Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                }
                            },
                            {
                                name: 'edit',
                                title: '查看',
                                extend:'data-area=["1000px","730px"]',
                                text:'查看',
                                //height:'500px',
                                classname: 'btn btn-xs btn-success btn-editone  btn-dialog',
                                url: 'violation/edit?ids={id}',
                                callback: function (data) {
                                    // console.log(11);
                                    // alert(11);
                                    // //Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    // Backend.api.refreshmenu(); //刷新菜单
                                    
                                }
                            },
                            
                        ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
